/*
 * Given the value of two nodes in a binary search tree, find the lowest common ancestor
 */
class CommonAncestor{
	public static Node findLowestCommonAncestor(Node root, Node value1, Node value2){
		while(root != null){
			int value = root.getValue();
			if (value > value1 && value > value2){
				root = root.getLeft();
			}else if (value < value1 && value <value2){
				root = root.getRight();
			}else {
				return root;
			}
		}
		return null;
	}
	
	// Overload it to handle nodes as well
	public static Node find(Node root, Node node1, Node node2){
		if(root == null||node1==null||node2==null) return null;
		return findLowestCommonAncestor(root, node1.getValue(), node2.getValue());
	}
}